package com.cai.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.cai.dao.MemberDao;
import com.cai.dao.OrderDao;
import com.cai.service.ReportService;
import com.cai.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private MemberDao memberDao;
    //运营数据统计
    public Map<String, Object> getBusinessReport() throws Exception {
        //获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取当前周一的日期
        String week = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取当前月的第一天
        String month=DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //今日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember =
                memberDao.findMemberCountAfterDate(week);
        //本月新增会员数
        Integer thisMonthNewMember =
                memberDao.findMemberCountAfterDate(month);
        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber =
                orderDao.findOrderCountAfterDate(week);
        //本月预约数
        Integer thisMonthOrderNumber =
                orderDao.findOrderCountAfterDate(month);
        //今日到诊数
        Integer todayVisitsNumber =
                orderDao.findVisitsCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber =
                orderDao.findVisitsCountAfterDate(week);
        //本月到诊数
        Integer thisMonthVisitsNumber =
                orderDao.findVisitsCountAfterDate(month);
        //热门套餐（取前4）
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        Map<String,Object> result = new HashMap<>();
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
